﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web
{
    public partial class Header : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            

        }

        protected string GetMenu(int id)
        {
            string menu = string.Empty;
            BLL.Categorys catBLL = new BLL.Categorys();
            DataSet ds = catBLL.GetList("parentId=" + id + " order by orderNo asc");
            menu += "<ul>";
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (HasSon(int.Parse(dr["categoryId"].ToString())))
                {
                    menu += "<li><a class=\"hide\" href=\"###\">" + dr["categoryName"] + "</a> ";
                    DataSet dss = catBLL.GetList("parentId=" + dr["categoryId"] + " order by OrderNo asc");
                    menu += "<ul>";
                    foreach (DataRow drr in dss.Tables[0].Rows)
                    {
                        menu += "<li><a href=\"ProductList.aspx?cid=" + drr["categoryId"] + "\">" + drr["categoryName"] + "</a> </li>";
                    }
                    menu += "</ul>";
                    menu += "</li>";
                }
                else
                {
                    menu += "<li><a href=\"ProductList.aspx?cid="+dr["categoryId"]+"\">" + dr["categoryName"] + "</a> </li>";
                }
            }
            menu += "</ul>";

            return menu;
        }

        protected bool HasSon(int id)
        {
            BLL.Categorys bll = new BLL.Categorys();
            DataSet ds = bll.GetList("parentId=" + id);
            if (ds.Tables[0].Rows.Count > 0)
                return true;
            else
                return false;
        }
    }
}